#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;
typedef enum { KEEP, TOLOWER, TOUPPER, REVERSE } CharFormat;
std::string formatMacAddress(const std::string& hwaddr, 
    							 const char delimiter='-', 
    							 CharFormat changeLower=KEEP);

std::string formatMacAddress(const std::string& hwaddr, 
							 const char delimiter,
							 CharFormat charFormat)
{
    std::string result = hwaddr; //default
    
    if ( ! ((delimiter>='0' && delimiter<='9') ||
    	    (delimiter>='A' && delimiter<='F') ||
    	    (delimiter>='a' && delimiter<='f')) )
   	{
	    std::string::size_type pos = hwaddr.find_first_not_of("0123456789ABCDEFabcdef");
	    if(std::string::npos != pos)
	    {
	    	char oldDelimiter = hwaddr.at(pos);
	    	if ( oldDelimiter != delimiter )
	    	{
	    		std::replace(result.begin(),result.end(),oldDelimiter,delimiter);
	    	}
	    	
	    	if (charFormat != KEEP)
	    	{
	    		for( std::string::iterator p=result.begin(); p!=result.end(); ++p)
	    		{
	    			switch(charFormat)
	    			{
	    			case TOLOWER: *p=tolower(*p); break;	    				
	    			case TOUPPER: *p=toupper(*p); break;
	    			case REVERSE: 
	    					if(isalpha(*p))
	    					{
	    						*p = isupper(*p)? tolower(*p):toupper(*p);
	    					}
	    					break;    						
					}
	    		}
	    	}
	    }
	}
    
    return result;
}

int main()
{
    string macAddress("12:AA:56:bb:90");
    cout << formatMacAddress(macAddress) << endl;
    cout << formatMacAddress(macAddress, '-') << endl;
    cout << formatMacAddress(macAddress, 'a') << endl;
    cout << formatMacAddress(macAddress, '@') << endl;
    cout << formatMacAddress(macAddress, '-', TOLOWER) << endl;
    cout << formatMacAddress(macAddress, '-', TOUPPER) << endl;
    cout << formatMacAddress(macAddress, '-', REVERSE) << endl;

    return 0;
}
